<template>
  <div class="logs">
    <filterPanel filterName="CLogsFilter" filterTitle="日志记录查询" :filterList="filterData"
                 @filterChange="filterChange"></filterPanel>
    <tablePanel tableName="CLogsTable" :tableLoading="loading" tableTitle="日志记录列表" :tableList="tableList"
                :tableData="tableData" :total="total" :currentPage="form.page_start" :pageSize="form.page_size"
                @sizeChange="sizeChange" @pageChange="pageChange">
      <zy-button type="primary" @click="exportUrl">导出列表</zy-button>
    </tablePanel>
  </div>
</template>

<script>
	export default {
		name: "CLogs",
		props: {},
		data() {
			return {
				filterData: [
					{
						title: '用户名',
						name: 'user',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '操作名称',
						name: 'actname',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '访问路径',
						name: 'actpath',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '访问时间',
						name: 'time',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
				],
				form: {
					status: "",
					time: [],
					page_start: 1,
					page_size: 10
				},
				loading: false,
				tableList: [
					{
						title: '用户名',
						width: 120,
						name: 'user',
						isShow: true,
						isSelected: true
					},
					{
						title: '操作名称',
						width: 120,
						name: 'actname',
						isShow: true,
						isSelected: true
					},
					{
						title: '访问路径',
						width: 120,
						name: 'actpath',
						isShow: true,
						isSelected: true
					},
					{
						title: '访问时间',
						width: 120,
						name: 'time',
						isShow: true,
						isSelected: true
					},
				],
				tableData: [],
				total: 0,
				download_url: ''
			};
		},
		computed: {
			postData() {
				let data = {
					...this.form,
					pagination: {
						page_start: this.form.page_start,
						page_size: this.form.page_size
					}
				};
				if (this.form.time && this.form.time.length > 0) {
					data.start_time = this.form.time[0] / 1000;
					data.end_time = this.form.time[1] / 1000;
				}
				return data;
			},
		},
		watch: {},
		components: {},
		methods: {
			sizeChange(val) {
				this.form.page_size = val;
				this.getData()
			},
			pageChange(val) {
				this.form.page_start = val;
				this.getData()
			},
			filterChange(data) {
				this.form = {...this.form, ...data};
				this.getData();
			},
			getData() {
				this.loading = true;
				this.$axios.post(this.$api.oprateLogs, this.postData).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.tableData = data.list.filter(item => {
							item.time = this.$Timestamp(item.time * 1000);
							return item;
						});
						this.download_url = data.download_url;
						this.total = data.pagination.total_count || 0;
					} else {
						this.total = 0;
						this.tableData = [];
					}
				}).catch(ret => {
					this.loading = false;
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			exportUrl() {
				this.$import_excal(this.download_url || "");
			}
		},
		mounted() {
			this.getData();
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/cooperate/logs/logs/index.less">

</style>
